#!bin/sh

if [ ! $DB_HOST ]; then
  DB_HOST='mongodb://mongo:27017/DOClever'
fi

if [ ! $FILE_PATH ]; then
  FILE_PATH="/root/DOClever-Server/data"
fi

if [ ! $PORT ]; then
  PORT="10001"
fi
touch /etc/supervisord.conf
cat >/etc/supervisord.conf<<-EOF 
[supervisord] 
nodaemon=true 
[program:DOClever] 
autorestart = true 
autostart = true 
stdout_logfile_maxbytes=100MB 
stdout_logfile=/tmp/debug.log 
stderr_logfile=/tmp/error.log 
command=/usr/bin/doclever 
EOF

touch /root/DOClever-Server/config.json
cat >/root/DOClever-Server/config.json<<-EOF
{"db":"$DB_HOST","filePath":"$FILE_PATH","port":$PORT}
EOF

# run supervisord
/usr/bin/supervisord -c /etc/supervisord.conf
